/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import dao.DAOAutomovel;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import model.Automovel;
import org.hibernate.HibernateException;

/**
 *
 * @author davi.filgueiras
 */
@ManagedBean(name = "ctrAutomovel")
@SessionScoped
public class CtrManterAutomovel {

    DAOAutomovel acessohibernateauto;
    private Automovel automovel;

    public CtrManterAutomovel() {
        acessohibernateauto = new DAOAutomovel();
    }

    public String salvar() {
        try {
            acessohibernateauto.gravar(getAutomovel());
            return "inc";
        } catch (HibernateException e) {
            return "falha";
        }
    }

    public List getAutomoveis() {
        try {
            return acessohibernateauto.carregarTudoOrdenado(Automovel.class, "marca");
        } catch (HibernateException e) {
            return null;
        }
    }

    public String excluir() {
        try {
            acessohibernateauto.excluir(automovel);
            return "exc";
        } catch (HibernateException e) {
            return "falha";
        }
    }

    public String alterar() {
        try {
            acessohibernateauto.alterar(automovel);
            return "alt";
        } catch (HibernateException e) {
            return "falha";
        }
    }

    public Automovel getAutomovel() {
        return automovel;
    }

    public void setAutomovel(Automovel automovel) {
        this.automovel = automovel;
    }
}
